<template>
	<view class="content">
		<view class="pageHeader">
			安全密码修改
			<a class="generalBack" @click="backpage()" hover-class="none">
			 <image src="/static/b-1.png" style="width: 18upx;height: 30upx;"></image>
			 </a>
		</view>
		<view class="regoodbox">
			<view class="flex aic" style="padding: 26upx 0;font-size: 28upx;color: #666;border-bottom: 2upx solid #EFEFEF;">
				<text style="padding-left: 20upx;width:200upx;">登录密码</text>
				<input type="password" placeholder="请输入登录密码" v-model="my_pwd"  class="modeinp"/>
			</view>	
			<view class="flex aic" style="padding: 26upx 0;font-size: 28upx;color: #666;border-bottom: 2upx solid #EFEFEF;">
				<text style="padding-left: 20upx;width: 200upx;">新安全密码</text>
				<input type="password" placeholder="不少于6位"  v-model="new_pwd" class="modeinp"/>
			</view>	
			<view class="flex aic" style="padding: 26upx 0;font-size: 28upx;color: #666;border-bottom: 2upx solid #EFEFEF;">
				<text style="padding-left: 20upx;width: 200upx;">确认安全密码</text>
				<input type="password" placeholder="请再次输入安全密码" v-model="confirm_new_pwd" class="modeinp"/>
			</view>
			<button @tap="modPwd()" class="surebtn">确认</button>
		</view>
	</view>
	</template>
	<script>
	import postAjax from '../../../API/postAjax.js'
	export default {
		data() {
			return {
				userToken:'',// token
				my_pwd:'',
				new_pwd:'',
				confirm_new_pwd:'',
			}
		},
		onLoad(options) {
			let that = this
			that.userToken = uni.getStorageSync('token')
		},
		methods: {
			// 返回上一页
			backpage(){
				uni.navigateBack({
					delta:1
				})
			},
			modPwd:function(){
				let that = this
								
				if(!that.my_pwd){
					uni.showToast({
					  title:'请输入登录密码',
					  icon:'none'
					})	
					return;
				}
				
				if(!that.new_pwd){
					uni.showToast({
					  title:'请输入新安全密码',
					  icon:'none'
					})	
					return;
				}
				
				if(!that.confirm_new_pwd){
					uni.showToast({
					  title:'请输入确认安全密码',
					  icon:'none'
					})	
					return;
				}
				
				
				if(that.new_pwd!=that.confirm_new_pwd){
					uni.showToast({
					  title:'新密码和确认密码不一致',
					  icon:'none'
					})	
					return;
				}
				
				postAjax('user/modPayPwd',{
					token:that.userToken,
					pwd:that.my_pwd,
					paypwd:that.new_pwd,
					confirm_pay_pwd:that.confirm_new_pwd
				},function(data){
						if(data.code==0){
							uni.showToast({
							  title:'修改成功',
							  icon:'none'
							})							
							let odata = uni.getStorageSync('loginfo')
							odata.paypwd = that.new_pwd
							uni.removeStorageSync('loginfo')
							uni.setStorageSync('loginfo', odata)
							uni.redirectTo({
								url:'../setting'
							})
						}else{
							uni.showToast({
							  title:'修改失败，请稍后重试',
							  icon:'none'
							})
						}
							
				})
			}
			
		}
	}
	
</script>

<style>
	.content{min-height: 100vh;background-color: #F9F9F9;}
	.pageHeader{width: 100%;height: 128upx;background-color: #1D84E8;line-height: 128upx;text-align: center;font-size: 36upx;color: #fff;padding-top: 40upx;}
	.generalBack{position: absolute;top:40upx;left:30upx;display: block;}
	.surebtn{display: block;font-size: 30upx;width:456upx;padding: 0;background:#1D84E8;color: #fff;margin: 260upx auto 0;}
	.surebtn::after{border: none;}
	.regoodbox{padding:0 30upx;}
	.modeinp{flex:1}
</style>
